package cn.yqx.bankshop.util;



import org.springframework.util.StringUtils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.sql.Blob;

public class BlobUtil {
	/*    */   public BlobUtil() {}
	/*    */   
	/*    */   public static String toString(Blob blob)
	/*    */   {
	/* 21 */     String result = null;
	/* 22 */     if (blob == null) return result;
	/*    */     try {
	/* 24 */       result = new String(blob.getBytes(1L, Long.valueOf(blob.length()).intValue()));
	/*    */     } catch (Exception e) {
	/*    */       try {
	/* 27 */         InputStream is = blob.getBinaryStream();
	/* 28 */         ByteArrayOutputStream out = new ByteArrayOutputStream();
	/* 29 */         byte[] buffer = new byte['?'];
	/* 30 */         int count; while ((count = is.read(buffer)) != -1) { 
	/* 31 */           out.write(buffer, 0, count);
	/*    */         }
	/* 33 */         result = new String(out.toByteArray());
	/*    */       } catch (Exception e1) {
	/* 35 */         e1.printStackTrace();
	/*    */       }
	/*    */     }
	/* 38 */     return result;
	/*    */   }
	/*    */   
	/*    */   public static byte[] toByte(String content) {
	/* 42 */     if (StringUtils.isEmpty(content)) {
	/*    */       try {
	/* 44 */         return content.getBytes("utf-8");
	/*    */       } catch (UnsupportedEncodingException e) {
	/* 46 */         e.printStackTrace();
	/*    */       }
	/*    */     }
	/* 49 */     return null;
	/*    */   }
	/*    */   
	/*    */   public static String toString(byte[] content) {
	/* 53 */     if (content != null) {
	/*    */       try {
	/* 55 */         return new String(content, "utf-8");
	/*    */       } catch (UnsupportedEncodingException e) {
	/* 57 */         e.printStackTrace();
	/*    */       }
	/*    */     }
	/* 60 */     return null;
	/*    */   }
	/*    */ }

